<?php
class MSetting extends CI_Model{

	public function __construct()
    {
        parent::__construct();
    }
/****---contract type****/    
    function getContractById($id){
	    $data = array();
	    $this->db->where('contracttype_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('contracttype');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getContractList(){
	     $query = $this->db->get('contracttype');
	     return $query->result();
	 }
     
     function addEditContract($id=0){
        $this->db->set('contracttype', db_clean($_POST['contracttype']));
        if($id > 0){
            $this->db->where('contracttype_id',$id);
            $this->db->update('contracttype');
        }else{
            $this->db->insert('contracttype');
        }  	 
	 }
	 
	 function deleteContract($id){
	 	$this->db->where('contracttype_id', id_clean($id));
		$this->db->delete('contracttype');	
	 }
/***---end---***/

/****---print type----***/
    function getPrintById($id){
	    $data = array();
	    $this->db->where('type_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('printtype');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getTypeList(){
	     $query = $this->db->get('printtype');
	     return $query->result();
	 }
     
     function addEditType($id=0){
        $this->db->set('type', db_clean($_POST['type']));
        if($id > 0){
            $this->db->where('type_id',$id);
            $this->db->update('printtype');
        }else{
            $this->db->insert('printtype');
        }  	 
	 }
	 
	 function deleteType($id){
	 	$this->db->where('type_id', id_clean($id));
		$this->db->delete('printtype');	
	 }
/***---end---***/

/****---Location----***/
    function getLocationById($id){
	    $data = array();
	    $this->db->where('location_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('location');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getLocationList(){
	     $query = $this->db->get('location');
	     return $query->result();
	 }
     
     function addEditLocation($id=0){
        $this->db->set('location', db_clean($_POST['location']));
        if($id > 0){
            $this->db->where('location_id',$id);
            $this->db->update('location');
        }else{
            $this->db->insert('location');
        }  	 
	 }
	 
	 function deleteLocation($id){
	 	$this->db->where('location_id', id_clean($id));
		$this->db->delete('location');	
	 }
/***---end---***/

/****---Assets----***/
    function getAssetById($cat,$id){
	    $data = array();
        if($cat==3){
            $table = "fatype";
            $field_id = "fatype_id";
        }
        else{
            $table = "natype";
            $field_id = "natype_id";
        }
        $this->db->select($field_id. " As id,".$table." As type");
	    $this->db->where($field_id,id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get($table);
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getAssetList($cat){
        if($cat==3){
            $table = "fatype";
            $field_id = "fatype_id";
        }
        else{
            $table = "natype";
            $field_id = "natype_id";
        }
        $this->db->select($field_id. " As id,".$table." As type");
        $query = $this->db->get($table);
        return $query->result();
	 }
     
     function addEditAsset($cat, $id=0){
        if($cat==3){
            $table = "fatype";
            $field_id = "fatype_id";
            //$type = "fatype";
        }
        else{
            $table = "natype";
            $field_id = "natype_id";
            //$type = "natype";
        }
        $this->db->set($table, db_clean($_POST['type']));
        if($id > 0){
            $this->db->where($field_id,$id);
            $this->db->update($table);
        }else{
            $this->db->insert($table);
        }  	 
	 }
	 
	 function deleteAsset($cat, $id){
	    if($cat==3){
            $table = "fatype";
            $field_id = "fatype_id";
        }
        else{
            $table = "natype";
            $field_id = "natype_id";
        }
        
	 	$this->db->where($field_id, id_clean($id));
		$this->db->delete($table);	
	 }
/***---end---***/

/****---IT category----***/
    function getITCategoryById($id){
	    $data = array();
	    $this->db->where('ittype_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('ittype');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getITCategoryList(){
	     $query = $this->db->get('ittype');
	     return $query->result();
	 }
     
     function addEditITCategory($id=0){
        $this->db->set('ittype', db_clean($_POST['ittype']));
        if($id > 0){
            $this->db->where('ittype_id',$id);
            $this->db->update('ittype');
        }else{
            $this->db->insert('ittype');
        }  	 
	 }
	 
	 function deleteitcat($id){
	 	$this->db->where('ittype_id', id_clean($id));
		$this->db->delete('ittype');	
	 }
/***---end---***/

/****---IT Model----***/
    function getITModelById($id){
	    $data = array();
	    $this->db->where('model_id',id_clean($id));
	    $this->db->limit(1);
	    $Q = $this->db->get('model');
	    if ($Q->num_rows() > 0){
	      $data = $Q->row_array();
	    }
	
	    $Q->free_result();    
	    return $data;    
	 }
		
	 function getITModelList(){
	     $query = $this->db->get('model');
	     return $query->result();
	 }
     
     function addEditITModel($id=0){
        $this->db->set('model', db_clean($_POST['model']));
        if($id > 0){
            $this->db->where('model_id',$id);
            $this->db->update('model');
        }else{
            $this->db->insert('model');
        }  	 
	 }
	 
	 function deleteModel($id){
	 	$this->db->where('model_id', id_clean($id));
		$this->db->delete('model');	
	 }
/***---end---***/
     
}


?>